Aperçu des variables
Les objets sf sont des data.frame.
Nous pouvons utiliser les fonctions head() ou summary().
library(sf)
com <- st_read("data/lot.gpkg", layer = "communes", quiet = TRUE)
head(com)
#> Simple feature collection with 6 features and 12 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: 556391.9 ymin: 6371852 xmax: 614866.5 ymax: 6418606
#> Projected CRS: RGF93 / Lambert-93
#> INSEE_COM NOM_COM STATUT POPULATION AGR_H AGR_F
#> 1 46001 Albas Commune simple 522 4.978581 0.000000
#> 2 46002 Albiac Commune simple 67 0.000000 9.589041
#> 3 46003 Alvignac Commune simple 706 10.419682 0.000000
#> 4 46004 Anglars Commune simple 219 0.000000 0.000000
#> 5 46005 Anglars-Juillac Commune simple 329 4.894895 4.894895
#> 6 46006 Anglars-Nozac Commune simple 377 4.840849 0.000000
#> IND_H IND_F BTP_H BTP_F TER_H TER_F
#> 1 4.936153 0.000000 9.957527 0.000000 44.917145 34.681799
#> 2 0.000000 0.000000 4.794521 0.000000 4.794521 9.589041
#> 3 10.419682 5.209841 10.419682 0.000000 57.308249 78.147612
#> 4 20.000000 15.000000 10.000000 0.000000 20.000000 20.000000
#> 5 4.894895 0.000000 0.000000 0.000000 29.369369 29.369369
#> 6 0.000000 0.000000 9.681698 4.840849 43.567639 38.726790
#> geom
#> 1 MULTIPOLYGON (((559262 6371...
#> 2 MULTIPOLYGON (((605540.7 64...
#> 3 MULTIPOLYGON (((593707.7 64...
#> 4 MULTIPOLYGON (((613211.3 64...
#> 5 MULTIPOLYGON (((556744.9 63...
#> 6 MULTIPOLYGON (((576667.2 64...
#> INSEE_COM NOM_COM STATUT POPULATION
#> Length:313 Length:313 Length:313 Min. : 49.0
#> Class :character Class :character Class :character 1st Qu.: 172.0
#> Mode :character Mode :character Mode :character Median : 300.0
#> Mean : 555.7
#> 3rd Qu.: 529.0
#> Max. :19907.0
#> AGR_H AGR_F IND_H IND_F
#> Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.000
#> 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 4.843 1st Qu.: 0.000
#> Median : 5.000 Median : 0.000 Median : 5.516 Median : 4.943
#> Mean : 6.935 Mean : 2.594 Mean : 16.395 Mean : 7.635
#> 3rd Qu.:10.013 3rd Qu.: 5.000 3rd Qu.: 19.715 3rd Qu.: 9.905
#> Max. :56.179 Max. :24.641 Max. :602.867 Max. :184.016
#> BTP_H BTP_F TER_H TER_F
#> Min. : 0.000 Min. : 0.0000 Min. : 0.00 Min. : 0.00
#> 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 10.00 1st Qu.: 15.15
#> Median : 5.000 Median : 0.0000 Median : 20.00 Median : 30.26
#> Mean : 9.572 Mean : 0.9723 Mean : 42.17 Mean : 60.77
#> 3rd Qu.: 10.329 3rd Qu.: 0.0000 3rd Qu.: 44.69 3rd Qu.: 63.95
#> Max. :203.122 Max. :16.9238 Max. :1778.87 Max. :2397.18
#> geom
#> MULTIPOLYGON :313
#> epsg:2154 : 0
#> +proj=lcc ...: 0
#>
#>
#>
Pour transformer un objet sf en data.frame “pur” nous pouvons utiliser les fonctions st_set_geometry() ou st_drop_geometry().
com_df1 <- st_set_geometry(com, NULL)
com_df2 <- st_drop_geometry(com)
identical(com_df1, com_df2)
#> INSEE_COM NOM_COM STATUT POPULATION AGR_H AGR_F
#> 1 46001 Albas Commune simple 522 4.978581 0.000000
#> 2 46002 Albiac Commune simple 67 0.000000 9.589041
#> 3 46003 Alvignac Commune simple 706 10.419682 0.000000
#> 4 46004 Anglars Commune simple 219 0.000000 0.000000
#> 5 46005 Anglars-Juillac Commune simple 329 4.894895 4.894895
#> 6 46006 Anglars-Nozac Commune simple 377 4.840849 0.000000
#> IND_H IND_F BTP_H BTP_F TER_H TER_F
#> 1 4.936153 0.000000 9.957527 0.000000 44.917145 34.681799
#> 2 0.000000 0.000000 4.794521 0.000000 4.794521 9.589041
#> 3 10.419682 5.209841 10.419682 0.000000 57.308249 78.147612
#> 4 20.000000 15.000000 10.000000 0.000000 20.000000 20.000000
#> 5 4.894895 0.000000 0.000000 0.000000 29.369369 29.369369
#> 6 0.000000 0.000000 9.681698 4.840849 43.567639 38.726790
Affichage
Aperçu des variables avec plot() :
#> Warning: plotting the first 9 out of 12 attributes; use max.plot = 12 to plot
#> all
Affichage d’une seule variable :
Affichage de la géométrie seule :
Il est aussi possible, comme nous l’avons vu précédement, d’utiliser le package mapsf pour afficher les objets sf
mf_map(com, col = "ivory4", border = "ivory")
Affichage interactif

Le package mapview (Appelhans et al., 2022) permet d’afficher facilement des objets sf sur une carte interactive.
library(mapview)
mapview(com)
Pour combiner des couches il suffit d’utiliser le +.
resto <- sf::st_read("data/lot.gpkg", layer = "restaurants", quiet = TRUE)
mapview(com) + mapview(resto)
Appelhans, T., Detsch, F., Reudenbach, C. et Woellauer, S. (2022).
mapview: Interactive Viewing of Spatial Data in R.
https://CRAN.R-project.org/package=mapview